package com.yufeng.collaboration.controller;

import com.yufeng.collaboration.entity.Message;
import com.yufeng.collaboration.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @GetMapping("/{receiverId}")
    public List<Message> getMessagesByReceiverId(@PathVariable Integer receiverId) {
        return messageService.getMessagesByReceiverId(receiverId);
    }

    @PostMapping
    public void sendMessage(@RequestBody Message message) {
        messageService.sendMessage(message);
    }

    @DeleteMapping("/{id}")
    public void deleteMessage(@PathVariable Integer id) {
        messageService.deleteMessage(id);
    }
}